﻿using Abp.AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;

namespace FutureApp.Shop.Dto
{
    /// <summary>
    /// 商品SKU
    /// </summary>
    [AutoMapTo(typeof(Goods))]
    public class CreateGoodsSKUInput
    {
        /// <summary>
        /// Id
        /// </summary>
        public Guid Id { get { return Guid.NewGuid(); } }

        /// <summary>
        /// 属性特征值
        /// </summary>
        public ICollection<Guid> AttrValues { get; set; }

        /// <summary>
        /// 库存数量
        /// </summary>
        public virtual int Quantity { get; set; }

        /// <summary>
        /// 价格
        /// </summary>
        public virtual decimal Price { get; set; }

        /// <summary>
        /// 促销价
        /// </summary>
        public virtual decimal SalePrice { get; set; }

        /// <summary>
        /// 最低价
        /// </summary>
        public virtual decimal BottomPrice { get; set; }

        /// <summary>
        /// 价格
        /// </summary>
        public CreateGoodsPriceInput Pricing
        {
            get
            {
                return new CreateGoodsPriceInput
                {
                    Id = this.Id,
                    Price = this.Price,
                    SalePrice = this.SalePrice,
                    BottomPrice = this.BottomPrice
                };
            }
        }

        /// <summary>
        /// 库存
        /// </summary>
        public CreateGoodsStockInput Stock
        {
            get
            {
                return new CreateGoodsStockInput
                {
                    Id = this.Id,
                    Quantity = this.Quantity
                };
            }
        }

        /// <summary>
        /// 商品特征属性分配值
        /// </summary>
        public ICollection<CreateGoodsAttributeDistributionInput> AttributeDistribution
        {
            get
            {
                return this.AttrValues
                    .Select(e => new CreateGoodsAttributeDistributionInput { GoodsId = this.Id, AttributeValueId = e })
                    .ToList();
            }
        }
    }
}
